home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / JTableHeader.java < prev    next >
Text File  |  1998-06-30  |  37KB  |  1,132 lines

  1. /*
  2.  * @(#)JTableHeader.java    1.25 98/03/30
  3.  *
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  *
  19.  */
  20.  
  21. package com.sun.java.swing.table;
  22.  
  23. import java.util.*;
  24. import java.awt.*;
  25. import java.awt.event.*;
  26. import com.sun.java.swing.*;
  27. import com.sun.java.swing.event.*;
  28. import java.awt.Dimension;
  29. import com.sun.java.swing.plaf.*;
  30. import java.beans.PropertyChangeListener;
  31. import com.sun.java.accessibility.*;
  32.  
  33. /**
  34.  * This is the column header part of a JTable.  I allow the user to
  35.  * change column widths and column ordering.  I share the same
  36.  * TableColumnModel with a JTable.
  37.  * <p>
  38.  * Warning: serialized objects of this class will not be compatible with
  39.  * future swing releases.  The current serialization support is appropriate
  40.  * for short term storage or RMI between Swing1.0 applications.  It will
  41.  * not be possible to load serialized Swing1.0 objects with future releases
  42.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  43.  * baseline for the serialized form of Swing objects.
  44.  *
  45.  * @version 1.25 03/30/98
  46.  * @author Alan Chung
  47.  * @author Philip Milne
  48.  * @see com.sun.java.swing.JTable
  49.  */
  50. public class JTableHeader extends JComponent implements TableColumnModelListener, Accessible
  51. {
  52. //
  53. // Instance Variables
  54. //
  55.     protected JTable table;
  56.  
  57.     /** The TableColumnModel of the table header*/
  58.     protected TableColumnModel    columnModel;
  59.  
  60.     /** Reordering of columns are allowed by the user */
  61.     protected boolean    reorderingAllowed;
  62.  
  63.     /** Resizing of columns are allowed by the user */
  64.     protected boolean    resizingAllowed;
  65.  
  66.     /**
  67.      * If this flag is true, then the header will repaint the table as
  68.      * a column is dragged or resized.
  69.      */
  70.     protected boolean    updateTableInRealTime;
  71.  
  72.     /** The index of the column being resized. 0 if not resizing */
  73.     transient protected TableColumn    resizingColumn;
  74.  
  75.     /** The index of the column being dragged. 0 if not dragging */
  76.     transient protected TableColumn    draggedColumn;
  77.  
  78.     /** The distance from its original position the column has been dragged */
  79.     transient protected int    draggedDistance;
  80.  
  81. //
  82. // Constructors
  83. //
  84.  
  85.     /**
  86.      *  Constructs a JTableHeader with a default TableColumnModel
  87.      *
  88.      * @see #createDefaultColumnModel()
  89.      */
  90.     public JTableHeader() {
  91.     this(null);
  92.     }
  93.  
  94.     /**
  95.      *  Constructs a JTableHeader which is initialized with
  96.      *  <i>cm</i> as the column model.  If <i>cm</i> is
  97.      *  <b>null</b> this method will initialize the table header
  98.      *  with a default TableColumnModel.
  99.      *
  100.      * @param cm    The column model for the table
  101.      * @see #createDefaultColumnModel()
  102.      */
  103.     public JTableHeader(TableColumnModel cm) {
  104.     super();
  105.  
  106.     if (cm == null)
  107.         cm = createDefaultColumnModel();
  108.     setColumnModel(cm);
  109.  
  110.     // Initalize local ivars
  111.     initializeLocalVars();
  112.  
  113.     // Get UI going
  114.     updateUI();
  115.     }
  116.  
  117. //
  118. // Local behavior attributes
  119. //
  120.  
  121.     /**  Sets the header's partner table to <I>aTable</I> */
  122.     public void setTable(JTable aTable) {
  123.     table = aTable;
  124.     }
  125.  
  126.     /** Returns the header's partner table */
  127.     public JTable getTable() {
  128.     return table;
  129.     }
  130.  
  131.     /**
  132.      *  Sets whether the user can drag column headers to reorder columns.
  133.      *
  134.      * @param    flag            true if the table view should allow
  135.      *                  reordering
  136.      * @see    #getReorderingAllowed
  137.      */
  138.     public void setReorderingAllowed(boolean b) {
  139.     reorderingAllowed = b;
  140.     }
  141.  
  142.     /**
  143.      * Returns true if the receiver allows the user to rearrange columns by
  144.      * dragging their headers, false otherwise. The default is true. You can
  145.      * rearrange columns programmatically regardless of this setting.
  146.      *
  147.      * @return    true if the receiver allows the user to rearrange columns by
  148.      *         dragging their headers, false otherwise
  149.      * @see    #setReorderingAllowed
  150.      */
  151.     public boolean getReorderingAllowed() {
  152.     return reorderingAllowed;
  153.     }
  154.  
  155.     /**
  156.      *  Sets whether the user can resize columns by dragging between headers.
  157.      *
  158.      * @param    flag            true if table view should allow
  159.      *                     resizing
  160.      * @see    #getResizingAllowed
  161.      */
  162.     public void setResizingAllowed(boolean b) {
  163.     resizingAllowed = b;
  164.     }
  165.  
  166.     /**
  167.      * Returns true if the receiver allows the user to resize columns by dragging
  168.      * between their headers, false otherwise. The default is true. You can
  169.      * resize columns programmatically regardless of this setting.
  170.      *
  171.      * @return    true if the receiver allows the user to resize columns by
  172.      *         dragging between their headers, false otherwise.
  173.      * @see    #setResizingAllowed
  174.      */
  175.     public boolean getResizingAllowed() {
  176.     return resizingAllowed;
  177.     }
  178.  
  179.     /**
  180.      * Returns the the dragged column, if and only if a drag is in
  181.      * process.
  182.      *
  183.      * @return    the the dragged column, if and only if a drag is in
  184.      *         process, otherwise returns null.
  185.      * @see    #getDraggedDistance
  186.      */
  187.     public TableColumn getDraggedColumn() {
  188.     return draggedColumn;
  189.     }
  190.  
  191.     /**
  192.      * Returns the column's horizontal distance from its original
  193.      * position, if and only if a drag is in process. Otherwise, the
  194.      * the return value is meaningless.
  195.      *
  196.      * @return    the column's horizontal distance from its original
  197.      *        position, if and only if a drag is in process
  198.      * @see    #getDraggedColumn
  199.      */
  200.     public int getDraggedDistance() {
  201.     return draggedDistance;
  202.     }
  203.  
  204.     /**
  205.      * Returns the resizing column.  If no column is being
  206.      * resized this method returns null.
  207.      *
  208.      * @return    the resizing column
  209.      */
  210.     public TableColumn getResizingColumn() {
  211.     return resizingColumn;
  212.     }
  213.  
  214.     /**
  215.      *  Sets whether the body of the table updates in real time when
  216.      *  a column is resized or dragged.
  217.      *
  218.      * @param    flag            true if tableView should update
  219.      *                    the body of the table in real time
  220.      * @see #getUpdateTableInRealTime
  221.      */
  222.     public void setUpdateTableInRealTime(boolean flag) {
  223.     updateTableInRealTime = flag;
  224.     }
  225.  
  226.     /**
  227.      * Returns true if the receiver updates the body of the table view in real
  228.      * time when a column is resized or dragged.  User can set this flag to
  229.      * false to speed up the table's response to user resize or drag actions.
  230.      * The default is true.
  231.      *
  232.      * @return    true if the table updates in real time
  233.      * @see #setUpdateTableInRealTime
  234.      */
  235.     public boolean getUpdateTableInRealTime() {
  236.     return updateTableInRealTime;
  237.     }
  238.  
  239.     /**
  240.      * Returns the index of the column that <I>point</I> lies in, or -1 if it
  241.      * lies outside the receiver's bounds.
  242.      *
  243.      * @return    the index of the column that <I>point</I> lies in, or -1 if it
  244.      *        lies outside the receiver's bounds
  245.      */
  246.     public int columnAtPoint(Point point) {
  247.     return getColumnModel().getColumnIndexAtX(point.x);
  248.     }
  249.  
  250.     /**
  251.      * Returns the rectangle containing the header tile at <I>columnIndex</I>.
  252.      *
  253.      * @return    the rectangle containing the header tile at <I>columnIndex</I>
  254.      * @exception IllegalArgumentException    If <I>columnIndex</I> is out
  255.      *                        of range
  256.      */
  257.     public Rectangle getHeaderRect(int columnIndex) {
  258.         // PENDING(philiip) The implementation should be delegated to the UI.
  259.     TableColumnModel columnModel = getColumnModel();
  260.  
  261.     if ((columnIndex < 0) || (columnIndex >= columnModel.getColumnCount())) {
  262.         throw new IllegalArgumentException("Column index out of range");
  263.     }
  264.  
  265.     int rectX = 0;
  266.     int column = 0;
  267.     int columnMargin = getColumnModel().getColumnMargin();
  268.     Enumeration enumeration = getColumnModel().getColumns();
  269.     while (enumeration.hasMoreElements()) {
  270.         TableColumn aColumn = (TableColumn)enumeration.nextElement();
  271.  
  272.         if (column == columnIndex) {
  273.         return new Rectangle(rectX, 0,
  274.                      aColumn.getWidth() + columnMargin,
  275.                      getSize().height);
  276.         }
  277.         rectX += aColumn.getWidth() + columnMargin;
  278.         column++;
  279.     }
  280.     return new Rectangle();
  281.     }
  282.  
  283.  
  284.     /**
  285.      * Overriding to allow renderer's tips to be used if it has
  286.      * text set.
  287.      */
  288.     public String getToolTipText(MouseEvent event) {
  289.     String tip = null;
  290.     Point p = event.getPoint();
  291.     int column;
  292.  
  293.     // Locate the renderer under the event location
  294.     if ((column = columnModel.getColumnIndexAtX(p.x)) != -1) {
  295.         TableColumn aColumn = columnModel.getColumn(column);
  296.         TableCellRenderer renderer = aColumn.getHeaderRenderer();
  297.         Component component = renderer.getTableCellRendererComponent(
  298.                   getTable(), aColumn.getHeaderValue(), false, false,
  299.                   -1, column);
  300.  
  301.         // Now have to see if the component is a JComponent before
  302.         // getting the tip
  303.         if (component instanceof JComponent) {
  304.         // Convert the event to the renderer's coordinate system
  305.         MouseEvent newEvent;
  306.         Rectangle cellRect = getHeaderRect(column);
  307.  
  308.         p.translate(-cellRect.x, -cellRect.y);
  309.         newEvent = new MouseEvent(component, event.getID(),
  310.                       event.getWhen(), event.getModifiers(),
  311.                       p.x, p.y, event.getClickCount(),
  312.                       event.isPopupTrigger());
  313.  
  314.         tip = ((JComponent)component).getToolTipText(newEvent);
  315.         }
  316.     }
  317.  
  318.     // No tip from the renderer get our own tip
  319.     if (tip == null)
  320.         tip = getToolTipText();
  321.  
  322.     return tip;
  323.     }
  324.  
  325. //
  326. // Managing TableHeaderUI
  327. //
  328.  
  329.     public TableHeaderUI getUI() {
  330.     return (TableHeaderUI)ui;
  331.     }
  332.  
  333.     public void setUI(TableHeaderUI ui){
  334.         if (this.ui != ui) {
  335.             super.setUI(ui);
  336.             repaint();
  337.         }
  338.     }
  339.  
  340.     public void updateUI(){
  341.     setUI((TableHeaderUI)UIManager.getUI(this));
  342.     resizeAndRepaint();
  343.     invalidate();//PENDING
  344.     }
  345.  
  346.  
  347.     /**
  348.      * @return "TableHeaderUI"
  349.      * @see JComponent#getUIClassID
  350.      * @see UIDefaults#getUI
  351.      */
  352.     public String getUIClassID() {
  353.     return "TableHeaderUI";
  354.     }
  355.  
  356.  
  357. //
  358. // Managing models
  359. //
  360.  
  361.     /**
  362.      *  Sets the column model for this table to <I>newModel</I> and registers
  363.      *  with for listner notifications from the new column model.
  364.      *
  365.      * @param    newModel    the new data source for this table
  366.      * @exception IllegalArgumentException    if <I>newModel</I> is null
  367.      * @see    #getColumnModel()
  368.      */
  369.     public void setColumnModel(TableColumnModel newModel) {
  370.     if (newModel == null) {
  371.         throw new IllegalArgumentException("Cannot set a null ColumnModel");
  372.     }
  373.  
  374.     TableColumnModel oldModel = columnModel;
  375.     if (newModel != oldModel) {
  376.         if (oldModel != null)
  377.         oldModel.removeColumnModelListener(this);
  378.  
  379.         columnModel = newModel;
  380.         newModel.addColumnModelListener(this);
  381.  
  382.         resizeAndRepaint();
  383.     }
  384.     }
  385.  
  386.     /**
  387.      * Returns the <B>TableColumnModel</B> that contains all column inforamtion
  388.      * of this table header.
  389.      *
  390.      * @return    the object that provides the column state of the table
  391.      * @see    #setColumnModel()
  392.      */
  393.     public TableColumnModel getColumnModel() {
  394.     return columnModel;
  395.     }
  396.  
  397.     public boolean isOpaque() {
  398.         return true;
  399.     }
  400.  
  401. //
  402. // Implementing TableColumnModelListener interface
  403. //
  404.  
  405.     public void columnAdded(TableColumnModelEvent e) { resizeAndRepaint(); }
  406.     public void columnRemoved(TableColumnModelEvent e) { resizeAndRepaint(); }
  407.     public void columnMoved(TableColumnModelEvent e) { repaint(); }
  408.     public void columnMarginChanged(ChangeEvent e) { resizeAndRepaint(); }
  409.     // Redrawing the header is slow in cell selection mode.
  410.     // Since header selection is ugly and it is always cler from the
  411.     // view which columns are selected, don't redraw the header.
  412.     public void columnSelectionChanged(ListSelectionEvent e) { } // repaint(); }
  413.  
  414. //
  415. //  Package Methods
  416. //
  417.  
  418.     /**
  419.      *  Returns the default column model object which is
  420.      *  a DefaultTableColumnModel.  Subclass can override this
  421.      *  method to return a different column model object
  422.      *
  423.      * @return the default column model object
  424.      */
  425.     protected TableColumnModel createDefaultColumnModel() {
  426.     return new DefaultTableColumnModel();
  427.     }
  428.  
  429.     protected void initializeLocalVars() {
  430.     table = null;
  431.     reorderingAllowed = true;
  432.     resizingAllowed = true;
  433.     draggedColumn = null;
  434.     draggedDistance = 0;
  435.     resizingColumn = null;
  436.     updateTableInRealTime = true;
  437.  
  438.     // I'm registered to do tool tips so we can draw tips for the
  439.     // renderers
  440.     ToolTipManager toolTipManager = ToolTipManager.sharedInstance();
  441.     toolTipManager.registerComponent(this);
  442.  
  443.     }
  444.  
  445.     /**
  446.      * Properly sizes the receiver and its header view, and marks it as
  447.      * needing display. Also resets cursor rectangles for the header view
  448.      * and line scroll amounts for the <B>JScrollPane</B>.
  449.      */
  450.     public void resizeAndRepaint() {
  451.         revalidate();
  452.     repaint();
  453.     }
  454.  
  455.     /**  Sets the header's draggedColumn to <I>aColumn</I> */
  456.     public void setDraggedColumn(TableColumn aColumn) {
  457.     draggedColumn = aColumn;
  458.     }
  459.  
  460.     /**  Sets the header's draggedDistance to <I>distance</I> */
  461.     public void setDraggedDistance(int distance) {
  462.     draggedDistance = distance;
  463.     }
  464.     /**  Sets the header's resizingColumn to <I>aColumn</I> */
  465.     public void setResizingColumn(TableColumn aColumn) {
  466.     resizingColumn = aColumn;
  467.     }
  468.  
  469. /////////////////
  470. // Accessibility support
  471. ////////////////
  472.  
  473.     /**
  474.      * Get the AccessibleContext associated with this JComponent
  475.      *
  476.      * @return the AccessibleContext of this JComponent
  477.      */
  478.     public AccessibleContext getAccessibleContext() {
  479.     if (accessibleContext == null) {
  480.         accessibleContext = new AccessibleJTableHeader();
  481.     }
  482.     return accessibleContext;
  483.     }
  484.  
  485.     //
  486.     // *** should also implement AccessibleSelction?
  487.     // *** and what's up with keyboard navigation/manipulation?
  488.     //
  489.     /**
  490.      * The class used to obtain the accessible role for this object.
  491.      * <p>
  492.      * Warning: serialized objects of this class will not be compatible with
  493.      * future swing releases.  The current serialization support is appropriate
  494.      * for short term storage or RMI between Swing1.0 applications.  It will
  495.      * not be possible to load serialized Swing1.0 objects with future releases
  496.      * of Swing.  The JDK1.2 release of Swing will be the compatibility
  497.      * baseline for the serialized form of Swing objects.
  498.      */
  499.     protected class AccessibleJTableHeader extends AccessibleJComponent {
  500.  
  501.         /**
  502.          * Get the role of this object.
  503.          *
  504.          * @return an instance of AccessibleRole describing the role of the
  505.      * object
  506.          * @see AccessibleRole
  507.          */
  508.         public AccessibleRole getAccessibleRole() {
  509.             return AccessibleRole.PANEL;
  510.         }
  511.  
  512.         /**
  513.          * Returns the Accessible child, if one exists, contained at the local
  514.          * coordinate Point.
  515.          *
  516.          * @param p The point defining the top-left corner of the Accessible,
  517.          * given in the coordinate space of the object's parent.
  518.          * @return the Accessible, if it exists, at the specified location;
  519.          * else null
  520.          */
  521.         public Accessible getAccessibleAt(Point p) {
  522.             int column;
  523.  
  524.             // Locate the renderer under the Point
  525.             if ((column = JTableHeader.this.columnAtPoint(p)) != -1) {
  526.                 TableColumn aColumn = JTableHeader.this.columnModel.getColumn(column);
  527.                 TableCellRenderer renderer = aColumn.getHeaderRenderer();
  528.                 Component component = renderer.getTableCellRendererComponent(
  529.                                   JTableHeader.this.getTable(),
  530.                                   aColumn.getHeaderValue(), false, false,
  531.                                   -1, column);
  532.  
  533.                 return new AccessibleJTableHeaderEntry(column, JTableHeader.this, JTableHeader.this.table);
  534.             } else {
  535.         return null;
  536.         }
  537.         }
  538.  
  539.         /**
  540.          * Returns the number of accessible children in the object.  If all
  541.          * of the children of this object implement Accessible, than this
  542.          * method should return the number of children of this object.
  543.          *
  544.          * @return the number of accessible children in the object.
  545.          */
  546.         public int getAccessibleChildrenCount() {
  547.             return JTableHeader.this.columnModel.getColumnCount();
  548.         }
  549.  
  550.         /**
  551.          * Return the nth Accessible child of the object.
  552.          *
  553.          * @param i zero-based index of child
  554.          * @return the nth Accessible child of the object
  555.          */
  556.         public Accessible getAccessibleChild(int i) {
  557.             if (i < 0 || i >= getAccessibleChildrenCount()) {
  558.                 return null;
  559.             } else {
  560.                 TableColumn aColumn = JTableHeader.this.columnModel.getColumn(i)
  561. ;
  562.                 TableCellRenderer renderer = aColumn.getHeaderRenderer();
  563.                 Component component = renderer.getTableCellRendererComponent(
  564.                                   JTableHeader.this.getTable(),
  565.                                   aColumn.getHeaderValue(), false, false,
  566.                                   -1, i);
  567.  
  568.                 return new AccessibleJTableHeaderEntry(i, JTableHeader.this, JTableHeader.this.table);
  569.             }
  570.         }
  571.  
  572.         protected class AccessibleJTableHeaderEntry extends AccessibleContext
  573.             implements Accessible, AccessibleComponent  {
  574.  
  575.             private JTableHeader parent;
  576.             private int column;
  577.         private JTable table;
  578.  
  579.             /**
  580.              *  Constructs an AccessiblJTableHeaaderEntry
  581.              */
  582.             public AccessibleJTableHeaderEntry(int c, JTableHeader p, JTable t) {
  583.                 parent = p;
  584.                 column = c;
  585.         table = t;
  586.         this.setAccessibleParent(parent);
  587.             }
  588.  
  589.             /**
  590.              * Get the AccessibleContext associated with this
  591.              *
  592.              * @return the AccessibleContext of this JComponent
  593.              */
  594.             public AccessibleContext getAccessibleContext() {
  595.                 return this;
  596.             }
  597.  
  598.         private AccessibleContext getCurrentAccessibleContext() {
  599.         TableColumnModel tcm = table.getColumnModel();
  600.                 if (tcm != null) {
  601.             TableColumn aColumn = tcm.getColumn(column);
  602.             TableCellRenderer renderer = aColumn.getHeaderRenderer();
  603.             Component c = renderer.getTableCellRendererComponent(
  604.                       JTableHeader.this.getTable(),
  605.                       aColumn.getHeaderValue(), false, false,
  606.                       -1, column);
  607.             if (c instanceof Accessible) {
  608.             return ((Accessible) c).getAccessibleContext();
  609.             }
  610.         }
  611.         return null;
  612.         }
  613.  
  614.         private Component getCurrentComponent() {
  615.         TableColumnModel tcm = table.getColumnModel();
  616.                 if (tcm != null) {
  617.             TableColumn aColumn = tcm.getColumn(column);
  618.             TableCellRenderer renderer = aColumn.getHeaderRenderer();
  619.             return renderer.getTableCellRendererComponent(
  620.                       JTableHeader.this.getTable(),
  621.                       aColumn.getHeaderValue(), false, false,
  622.                       -1, column);
  623.         } else {
  624.             return null;
  625.         }
  626.             }
  627.  
  628.         // AccessibleContext methods
  629.  
  630.             public String getAccessibleName() {
  631.                 AccessibleContext ac = getCurrentAccessibleContext();
  632.                 if (ac != null) {
  633.             String name = ac.getAccessibleName();
  634.                     if ((name != null) && (name != "")) {
  635.             return ac.getAccessibleName();
  636.             }
  637.                 }
  638.         if ((accessibleName != null) && (accessibleName != "")) {
  639.             return accessibleName;
  640.         } else {
  641.                     return table.getColumnName(column);
  642.                 }
  643.             }
  644.  
  645.             public void setAccessibleName(String s) {
  646.                 AccessibleContext ac = getCurrentAccessibleContext();
  647.                 if (ac != null) {
  648.                     ac.setAccessibleName(s);
  649.                 } else {
  650.             super.setAccessibleName(s);
  651.         }
  652.             }
  653.  
  654.         //
  655.         // *** should check toolip text for desc. (needs MouseEvent)
  656.         //
  657.             public String getAccessibleDescription() {
  658.                 AccessibleContext ac = getCurrentAccessibleContext();
  659.                 if (ac != null) {
  660.                     return ac.getAccessibleDescription();
  661.                 } else {
  662.                     return super.getAccessibleDescription();
  663.                 }
  664.             }
  665.  
  666.             public void setAccessibleDescription(String s) {
  667.                 AccessibleContext ac = getCurrentAccessibleContext();
  668.                 if (ac != null) {
  669.                     ac.setAccessibleDescription(s);
  670.                 } else {
  671.             super.setAccessibleDescription(s);
  672.         }
  673.             }
  674.  
  675.             public AccessibleRole getAccessibleRole() {
  676.                 AccessibleContext ac = getCurrentAccessibleContext();
  677.                 if (ac != null) {
  678.                     return ac.getAccessibleRole();
  679.                 } else {
  680.                     return AccessibleRole.COLUMN_HEADER;
  681.                 }
  682.             }
  683.  
  684.             public AccessibleStateSet getAccessibleStateSet() {
  685.                 AccessibleContext ac = getCurrentAccessibleContext();
  686.                 if (ac != null) {
  687.                     return ac.getAccessibleStateSet();
  688.                 } else {
  689.                     return new AccessibleStateSet();  // must be non null?
  690.                 }
  691.             }
  692.  
  693.             public int getAccessibleIndexInParent() {
  694.                 return column;
  695.             }
  696.  
  697.             public int getAccessibleChildrenCount() {
  698.                 AccessibleContext ac = getCurrentAccessibleContext();
  699.                 if (ac != null) {
  700.                     return ac.getAccessibleChildrenCount();
  701.                 } else {
  702.                     return 0;
  703.                 }
  704.             }
  705.  
  706.             public Accessible getAccessibleChild(int i) {
  707.                 AccessibleContext ac = getCurrentAccessibleContext();
  708.                 if (ac != null) {
  709.                     Accessible accessibleChild = ac.getAccessibleChild(i);
  710.             ac.setAccessibleParent(this);
  711.             return accessibleChild;
  712.                 } else {
  713.                     return null;
  714.                 }
  715.             }
  716.  
  717.             public Locale getLocale() {
  718.                 AccessibleContext ac = getCurrentAccessibleContext();
  719.                 if (ac != null) {
  720.                     return ac.getLocale();
  721.                 } else {
  722.                     return null;
  723.                 }
  724.             }
  725.  
  726.             public void addPropertyChangeListener(PropertyChangeListener l) {
  727.                 AccessibleContext ac = getCurrentAccessibleContext();
  728.                 if (ac != null) {
  729.                     ac.addPropertyChangeListener(l);
  730.                 } else {
  731.             super.addPropertyChangeListener(l);
  732.         }
  733.             }
  734.  
  735.             public void removePropertyChangeListener(PropertyChangeListener l) {
  736.                 AccessibleContext ac = getCurrentAccessibleContext();
  737.                 if (ac != null) {
  738.                     ac.removePropertyChangeListener(l);
  739.                 } else {
  740.             super.removePropertyChangeListener(l);
  741.         }
  742.             }
  743.  
  744.         public AccessibleAction getAccessibleAction() {
  745.                 return getCurrentAccessibleContext().getAccessibleAction();
  746.         }
  747.  
  748.         public AccessibleComponent getAccessibleComponent() {
  749.                 return this; // to override getBounds()
  750.         }
  751.  
  752.         public AccessibleSelection getAccessibleSelection() {
  753.                 return getCurrentAccessibleContext().getAccessibleSelection();
  754.         }
  755.  
  756.         public AccessibleText getAccessibleText() {
  757.                 return getCurrentAccessibleContext().getAccessibleText();
  758.         }
  759.  
  760.         public AccessibleValue getAccessibleValue() {
  761.                 return getCurrentAccessibleContext().getAccessibleValue();
  762.         }
  763.  
  764.  
  765.         // AccessibleComponent methods
  766.  
  767.             public Color getBackground() {
  768.                 AccessibleContext ac = getCurrentAccessibleContext();
  769.                 if (ac instanceof AccessibleComponent) {
  770.                     return ((AccessibleComponent) ac).getBackground();
  771.                 } else {
  772.             Component c = getCurrentComponent();
  773.             if (c != null) {
  774.                         return c.getBackground();
  775.             } else {
  776.             return null;
  777.             }
  778.                 }
  779.             }
  780.  
  781.             public void setBackground(Color c) {
  782.                 AccessibleContext ac = getCurrentAccessibleContext();
  783.                 if (ac instanceof AccessibleComponent) {
  784.                     ((AccessibleComponent) ac).setBackground(c);
  785.                 } else {
  786.                     Component cp = getCurrentComponent();
  787.                     if (cp != null) {
  788.                         cp.setBackground(c);
  789.                     }
  790.                 }
  791.             }
  792.  
  793.             public Color getForeground() {
  794.                 AccessibleContext ac = getCurrentAccessibleContext();
  795.                 if (ac instanceof AccessibleComponent) {
  796.                     return ((AccessibleComponent) ac).getForeground();
  797.                 } else {
  798.                     Component c = getCurrentComponent();
  799.                     if (c != null) {
  800.                         return c.getForeground();
  801.                     } else {
  802.             return null;
  803.             }
  804.                 }
  805.             }
  806.  
  807.             public void setForeground(Color c) {
  808.                 AccessibleContext ac = getCurrentAccessibleContext();
  809.                 if (ac instanceof AccessibleComponent) {
  810.                     ((AccessibleComponent) ac).setForeground(c);
  811.                 } else {
  812.                     Component cp = getCurrentComponent();
  813.                     if (cp != null) {
  814.                         cp.setForeground(c);
  815.                     }
  816.                 }
  817.             }
  818.  
  819.             public Cursor getCursor() {
  820.                 AccessibleContext ac = getCurrentAccessibleContext();
  821.                 if (ac instanceof AccessibleComponent) {
  822.                     return ((AccessibleComponent) ac).getCursor();
  823.                 } else {
  824.                     Component c = getCurrentComponent();
  825.                     if (c != null) {
  826.                         return c.getCursor();
  827.                     } else {
  828.             Accessible ap = getAccessibleParent();
  829.             if (ap instanceof AccessibleComponent) {
  830.                 return ((AccessibleComponent) ap).getCursor();
  831.             } else {
  832.                 return null;
  833.             }
  834.             }
  835.                 }
  836.             }
  837.  
  838.             public void setCursor(Cursor c) {
  839.                 AccessibleContext ac = getCurrentAccessibleContext();
  840.                 if (ac instanceof AccessibleComponent) {
  841.                     ((AccessibleComponent) ac).setCursor(c);
  842.                 } else {
  843.                     Component cp = getCurrentComponent();
  844.                     if (cp != null) {
  845.                         cp.setCursor(c);
  846.             }
  847.                 }
  848.             }
  849.  
  850.             public Font getFont() {
  851.                 AccessibleContext ac = getCurrentAccessibleContext();
  852.                 if (ac instanceof AccessibleComponent) {
  853.                     return ((AccessibleComponent) ac).getFont();
  854.                 } else {
  855.                     Component c = getCurrentComponent();
  856.                     if (c != null) {
  857.                         return c.getFont();
  858.             } else {
  859.             return null;
  860.             }
  861.                 }
  862.             }
  863.  
  864.             public void setFont(Font f) {
  865.                 AccessibleContext ac = getCurrentAccessibleContext();
  866.                 if (ac instanceof AccessibleComponent) {
  867.                     ((AccessibleComponent) ac).setFont(f);
  868.                 } else {
  869.                     Component c = getCurrentComponent();
  870.                     if (c != null) {
  871.                         c.setFont(f);
  872.             }
  873.         }
  874.             }
  875.  
  876.             public FontMetrics getFontMetrics(Font f) {
  877.                 AccessibleContext ac = getCurrentAccessibleContext();
  878.                 if (ac instanceof AccessibleComponent) {
  879.                     return ((AccessibleComponent) ac).getFontMetrics(f);
  880.                 } else {
  881.                     Component c = getCurrentComponent();
  882.                     if (c != null) {
  883.                         return c.getFontMetrics(f);
  884.             } else {
  885.             return null;
  886.             }
  887.                 }
  888.             }
  889.  
  890.             public boolean isEnabled() {
  891.                 AccessibleContext ac = getCurrentAccessibleContext();
  892.                 if (ac instanceof AccessibleComponent) {
  893.                     return ((AccessibleComponent) ac).isEnabled();
  894.                 } else {
  895.                     Component c = getCurrentComponent();
  896.                     if (c != null) {
  897.                         return c.isEnabled();
  898.                     } else {
  899.             return false;
  900.             }
  901.                 }
  902.             }
  903.  
  904.             public void setEnabled(boolean b) {
  905.                 AccessibleContext ac = getCurrentAccessibleContext();
  906.                 if (ac instanceof AccessibleComponent) {
  907.                     ((AccessibleComponent) ac).setEnabled(b);
  908.                 } else {
  909.                     Component c = getCurrentComponent();
  910.                     if (c != null) {
  911.                         c.setEnabled(b);
  912.                     }
  913.                 }
  914.             }
  915.  
  916.             public boolean isVisible() {
  917.                 AccessibleContext ac = getCurrentAccessibleContext();
  918.                 if (ac instanceof AccessibleComponent) {
  919.                     return ((AccessibleComponent) ac).isVisible();
  920.                 } else {
  921.                     Component c = getCurrentComponent();
  922.                     if (c != null) {
  923.                         return c.isVisible();
  924.                     } else {
  925.                         return false;
  926.                     }
  927.                 }
  928.             }
  929.  
  930.             public void setVisible(boolean b) {
  931.                 AccessibleContext ac = getCurrentAccessibleContext();
  932.                 if (ac instanceof AccessibleComponent) {
  933.                     ((AccessibleComponent) ac).setVisible(b);
  934.                 } else {
  935.                     Component c = getCurrentComponent();
  936.                     if (c != null) {
  937.                         c.setVisible(b);
  938.                     }
  939.                 }
  940.             }
  941.  
  942.             public boolean isShowing() {
  943.                 AccessibleContext ac = getCurrentAccessibleContext();
  944.                 if (ac instanceof AccessibleComponent) {
  945.                     return ((AccessibleComponent) ac).isShowing();
  946.                 } else {
  947.                     Component c = getCurrentComponent();
  948.                     if (c != null) {
  949.                         return c.isShowing();
  950.                     } else {
  951.                         return false;
  952.                     }
  953.                 }
  954.             }
  955.  
  956.             public boolean contains(Point p) {
  957.                 AccessibleContext ac = getCurrentAccessibleContext();
  958.                 if (ac instanceof AccessibleComponent) {
  959.                     Rectangle r = ((AccessibleComponent) ac).getBounds();
  960.                     return r.contains(p);
  961.                 } else {
  962.                     Component c = getCurrentComponent();
  963.                     if (c != null) {
  964.             Rectangle r = c.getBounds();
  965.                         return r.contains(p);
  966.                     } else {
  967.                         return getBounds().contains(p);
  968.                     }
  969.         }
  970.             }
  971.  
  972.             public Point getLocationOnScreen() {
  973.                 if (parent != null) {
  974.                     Point parentLocation = parent.getLocationOnScreen();
  975.                     Point componentLocation = getLocation();
  976.                     componentLocation.translate(parentLocation.x, parentLocation.y);
  977.                     return componentLocation;
  978.                 } else {
  979.                     return null;
  980.                 }
  981.             }
  982.  
  983.             public Point getLocation() {
  984.                 AccessibleContext ac = getCurrentAccessibleContext();
  985.                 if (ac instanceof AccessibleComponent) {
  986.                     Rectangle r = ((AccessibleComponent) ac).getBounds();
  987.                     return r.getLocation();
  988.                 } else {
  989.                     Component c = getCurrentComponent();
  990.                     if (c != null) {
  991.             Rectangle r = c.getBounds();
  992.                         return r.getLocation();
  993.                     } else {
  994.                         return getBounds().getLocation();
  995.                     }
  996.         }
  997.             }
  998.  
  999.             public void setLocation(Point p) {
  1000. //                if ((parent != null)  && (parent.contains(p))) {
  1001. //                    ensureIndexIsVisible(indexInParent);
  1002. //                }
  1003.             }
  1004.  
  1005.             public Rectangle getBounds() {
  1006.                   Rectangle r = table.getCellRect(-1, column, false);
  1007.                   r.y = 0;
  1008.                   return r;
  1009.  
  1010. //                AccessibleContext ac = getCurrentAccessibleContext();
  1011. //                if (ac instanceof AccessibleComponent) {
  1012. //                    return ((AccessibleComponent) ac).getBounds();
  1013. //                } else {
  1014. //            Component c = getCurrentComponent();
  1015. //            if (c != null) {
  1016. //            return c.getBounds();
  1017. //            } else {
  1018. //            Rectangle r = table.getCellRect(-1, column, false);
  1019. //            r.y = 0;
  1020. //            return r;
  1021. //            }
  1022. //        }
  1023.             }
  1024.  
  1025.             public void setBounds(Rectangle r) {
  1026.                 AccessibleContext ac = getCurrentAccessibleContext();
  1027.                 if (ac instanceof AccessibleComponent) {
  1028.                     ((AccessibleComponent) ac).setBounds(r);
  1029.                 } else {
  1030.             Component c = getCurrentComponent();
  1031.             if (c != null) {
  1032.             c.setBounds(r);
  1033.             }
  1034.         }
  1035.             }
  1036.  
  1037.             public Dimension getSize() {
  1038.         return getBounds().getSize();
  1039. //                AccessibleContext ac = getCurrentAccessibleContext();
  1040. //                if (ac instanceof AccessibleComponent) {
  1041. //                    Rectangle r = ((AccessibleComponent) ac).getBounds();
  1042. //                    return r.getSize();
  1043. //                } else {
  1044. //                    Component c = getCurrentComponent();
  1045. //                    if (c != null) {
  1046. //                        Rectangle r = c.getBounds();
  1047. //                        return r.getSize();
  1048. //                    } else {
  1049. //                        return getBounds().getSize();
  1050. //                    }
  1051. //                }
  1052.             }
  1053.  
  1054.             public void setSize (Dimension d) {
  1055.                 AccessibleContext ac = getCurrentAccessibleContext();
  1056.                 if (ac instanceof AccessibleComponent) {
  1057.                     ((AccessibleComponent) ac).setSize(d);
  1058.                 } else {
  1059.             Component c = getCurrentComponent();
  1060.             if (c != null) {
  1061.             c.setSize(d);
  1062.             }
  1063.         }
  1064.             }
  1065.  
  1066.             public Accessible getAccessibleAt(Point p) {
  1067.                 AccessibleContext ac = getCurrentAccessibleContext();
  1068.                 if (ac instanceof AccessibleComponent) {
  1069.                     return ((AccessibleComponent) ac).getAccessibleAt(p);
  1070.                 } else {
  1071.                     return null;
  1072.                 }
  1073.             }
  1074.  
  1075.             public boolean isFocusTraversable() {
  1076.                 AccessibleContext ac = getCurrentAccessibleContext();
  1077.                 if (ac instanceof AccessibleComponent) {
  1078.                     return ((AccessibleComponent) ac).isFocusTraversable();
  1079.                 } else {
  1080.             Component c = getCurrentComponent();
  1081.             if (c != null) {
  1082.             return c.isFocusTraversable();
  1083.             } else {
  1084.             return false;
  1085.             }
  1086.                 }
  1087.             }
  1088.  
  1089.             public void requestFocus() {
  1090.                 AccessibleContext ac = getCurrentAccessibleContext();
  1091.                 if (ac instanceof AccessibleComponent) {
  1092.                     ((AccessibleComponent) ac).requestFocus();
  1093.                 } else {
  1094.             Component c = getCurrentComponent();
  1095.             if (c != null) {
  1096.             c.requestFocus();
  1097.             }
  1098.         }
  1099.             }
  1100.  
  1101.             public void addFocusListener(FocusListener l) {
  1102.                 AccessibleContext ac = getCurrentAccessibleContext();
  1103.                 if (ac instanceof AccessibleComponent) {
  1104.                     ((AccessibleComponent) ac).addFocusListener(l);
  1105.                 } else {
  1106.             Component c = getCurrentComponent();
  1107.             if (c != null) {
  1108.             c.addFocusListener(l);
  1109.             }
  1110.         }
  1111.             }
  1112.  
  1113.             public void removeFocusListener(FocusListener l) {
  1114.                 AccessibleContext ac = getCurrentAccessibleContext();
  1115.                 if (ac instanceof AccessibleComponent) {
  1116.                     ((AccessibleComponent) ac).removeFocusListener(l);
  1117.                 } else {
  1118.                     Component c = getCurrentComponent();
  1119.                     if (c != null) {
  1120.                         c.removeFocusListener(l);
  1121.                     }
  1122.                 }
  1123.             }
  1124.  
  1125.         } // inner class AccessibleJTableHeaderElement
  1126.  
  1127.     }  // inner class AccessibleJTableHeader
  1128.  
  1129. }  // End of Class JTableHeader
  1130.  
  1131.  
  1132.